package top.leyi.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import top.leyi.entity.Class;
import top.leyi.entity.Course;

import java.util.List;

public interface CourseMappper {

    /*
     根据班级查询cid, 根据热度排序
     */
    @Select("SELECT id FROM course c  where c.classId = #{value} ORDER BY c.hot DESC")
    List<Integer> queryCidByClassIdSort(String  id);

    /*
     根据班级查询cid , 根据id排序
    */
    @Select("SELECT id FROM course c  where c.classId = #{value} ORDER BY id DESC LIMIT 1 OFFSET 0")
    String queryCidByClassId(String  id);
    /*
     根据班级查询cid , 根据id排序
     */
    @Select("SELECT id FROM course c  where c.owner = #{owner} and c.classId = #{classId}")
    String ownerIsExist(Course course);

    /*
     根据cid查询课程表
     */
    @Select("SELECT * FROM  course_details cd join course c on c.id = cd.cid WHERE cd.cid = #{value}")
    List<Course> queryCoursesDetailsByCid(int  id);

    /*
      插入一个course
      */
    @Insert("INSERT INTO course(classId, owner) VALUES(#{classId}, #{owner}) ")
    void addOneCourse(Course course);
    /*
      插入一个course_details
        */
    @Insert("INSERT INTO course_details(xqj, djj, dsz, qsz, jsz, teacher, room, name, cid)" +
            " VALUES(#{xqj},#{djj},#{dsz},#{qsz},#{jsz},#{teacher},#{room},#{name},#{cid})")
    void addOneCourseDetails(Course course);

    /*
        插入多个course_details

    @Insert("INSERT INTO course_details(xqj, djj, dsz, qsz, jsz, teacher, room, name, cid)" +
            " VALUES(#{xqj},#{djj},#{dsz},#{qsz},#{jsz},#{teacher},#{room},#{name},#{cid})")
    void addManyCourseDetails(List<Course> courses);

    */


}
